﻿@page "/PorcessInfo"
<h3>进程信息</h3>

<MButton OnClick="QueryAll">查询进程</MButton>
<MButton OnClick="QueryJavaPoress">查询Java进程</MButton>
<MButton OnClick="QueryDotnetPoress">查询DotNet</MButton>

<tr>
    <td>用户名</td>
    <td>进程 ID</td>
    <td>Cpu使用率</td>
    <td>内存使用率</td>
    <td>虚拟内存大小</td>
    <td>驻留集大小</td>
    <td>终端</td>
    <td>进程状态</td>
    <td>启动时间</td>
    <td>运行时间</td>
    <td>命令</td>
    <td>操作</td>
</tr>
@foreach (var item in linuxRunningProcesseList)
{
    <tr>
        <td>@item.User</td>
        <td>@item.Pid</td>
        <td>@item.CpuUsage</td>
        <td>@item.MemoryUsage</td>
        <td>@item.VsZ</td>
        <td>@item.Rss</td>
        <td>@item.Tty</td>
        <td>@item.Stat</td>
        <td>@item.Start</td>
        <td>@item.Time</td>
        <td>@item.Command</td>
        <td><MButton OnClick="()=>ShutDown(item.Pid)">终止</MButton></td>
    </tr>
}


@code {
    [Inject]
    public ISshClientService SshClientService { get; set; }

    private List<LinuxRunningProcess> linuxRunningProcesseList = new List<LinuxRunningProcess>();

    /// <summary>
    /// /查询进程命令
    /// </summary>
    private QueryPorcessCommand queryPorcessCommand = new QueryPorcessCommand();

    /// <summary>
    /// 查询Java进程
    /// </summary>
    public void QueryJavaPoress(){
        queryPorcessCommand.AppRuntimeType = EasyDevOps.Shared.Models.Enums.AppRuntimeTypeEnum.Java;
        QueryPoress();
    }

    /// <summary>
    /// 查询Dotnet进程
    /// </summary>
    public void QueryDotnetPoress(){
        queryPorcessCommand.AppRuntimeType = EasyDevOps.Shared.Models.Enums.AppRuntimeTypeEnum.Dotnet;
        QueryPoress();
    }

    public void QueryAll(){
        queryPorcessCommand.AppRuntimeType = null;
        QueryPoress();
    }
    /// <summary>
    /// 查询进程
    /// </summary>
    public void QueryPoress(){
        var linuxCommandResultBase = SshClientService.ExecuteCommand<QueryPorcessCommand, LinuxRunningProcess>(queryPorcessCommand);
        linuxRunningProcesseList = linuxCommandResultBase.OutData;
    }
    /// <summary>
    /// 终止进程
    /// </summary>
    /// <param name="pid"></param>
    public void ShutDown(int pid){
        SshClientService.ExecuteCommand(() => new ShutDownPorcessCommand() { pid = pid.ToString() });
    }
}
